package org.seed.quantum.example.ssl;

import org.seed.quantum.example.api.DemoApi;
import org.seed.quantum.example.api.DemoParam;
import org.seed.quantum.example.api.DemoRst;
import org.seed.quantum.message.plugins.SslPlugin;
import org.seed.quantum.message.rpc.RpcConsumerProcessor;
import org.seed.quantum.protocol.RpcProtocol;
import org.seed.quantum.socket.SocketClient;

import java.io.IOException;

public class RpcConsumerDemo {

    public static void main(String[] args) throws IOException {
        RpcConsumerProcessor rpcConsumerProcessor = new RpcConsumerProcessor();


        SslPlugin sslPlugin = new SslPlugin(null);
        sslPlugin.initForClient(RpcConsumerDemo.class.getClassLoader().getResourceAsStream("server.keystore"), "123456");
        rpcConsumerProcessor.addPlugin(sslPlugin);
        SocketClient consumer = new SocketClient("localhost", 8888, new RpcProtocol(), rpcConsumerProcessor);
        consumer.start();

        DemoApi demoApi = rpcConsumerProcessor.getObject(DemoApi.class);
        DemoRst rst = demoApi.getEntityRst(new DemoParam(1L,"Guanglin Gao"));
        System.out.println("expected : Guanglin Gao:1");
        System.out.println(rst.toString());
        System.out.println("------------------------");
        rst =  demoApi.getBoxedParamType(1,5.5);
        System.out.println("expected : 6.5");
        System.out.println(rst.toString());
        System.out.println("------------------------");
        String s = demoApi.getStringRst();
        System.out.println("expected : Hello String");
        System.out.println(s);
        System.out.println("------------------------");
        rst = demoApi.getPrimaryParamType(1,2.3f);
        System.out.println("expected : 3.3");
        System.out.println(rst.toString());



    }
}
